﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace cityinfo
{
    public class City
    {
        private string m_name;
        private string m_state;
        private string m_country;
        private string m_location;

        public City()
        {
            m_name = "";
            m_state = "";
            m_country = "";
            m_location = "";
        }
        public City(XmlNode citynode)
        {
            m_name = citynode.Attributes.GetNamedItem("city").Value;
            m_state = citynode.Attributes.GetNamedItem("state").Value;
            m_location = citynode.Attributes.GetNamedItem("location").Value;
            m_country = "United States of America";
            if (IsInternationalCity())
            {
                int state1 = m_state.IndexOf("(");
                int state2 = m_state.IndexOf(")");
                if (state1 > 0 && state1 < state2)
                {
                    m_country = m_state.Substring(0, state1);
                }
                else
                {
                    m_country = m_state;
                }
            }

        }
        public bool IsUSCity()
        {
            return !IsInternationalCity();
        }
        public bool IsInternationalCity()
        {
            return m_location.Length > 0 && m_location.IndexOf("|") > 0;
        }
        public string Country
        {
            get { return m_country; }
            set { m_country = value; }
        }
        public string Name
        {
            get { return m_name; }
            set { m_name = value; }
        }
        public string State
        {
            get { return m_state; }
            set { m_state = value; }
        }
        public string Location
        {
            get { return m_location; }
            set { m_location = value; }
        }
    }
}
